/* File makes Table 6 */

/* 	Input files: 	fw_likes
	Output files: T6_Likes.tex */

**********************************************
clear all
macro drop _all
scalar drive		= "E:"
scalar maindir		= "`=drive'\Replicate"
scalar tabledir		= "`=drive'\Replicate\TablesRep"
cd "`=maindir'"
**********************************************
 
use fw_likes, clear  

foreach var of varlist _all {
	qui replace `var'=0 if `var'==.  
}


foreach xx in bull bear {
gen sum_`xx'_likes_2_10 = sum_`xx'_likes_2 + sum_`xx'_likes_3 + sum_`xx'_likes_4 + sum_`xx'_likes_5 + sum_`xx'_likes_6 + sum_`xx'_likes_7 + sum_`xx'_likes_8 + sum_`xx'_likes_9 + sum_`xx'_likes_10
gen sum_`xx'_likes_11_30 = sum_`xx'_likes_11_20 + sum_`xx'_likes_21_30 
gen sum_`xx'_likes_31_50 = sum_`xx'_likes_31_40 + sum_`xx'_likes_41_50 
}

foreach i in 1 2_10 11_30 31_50 {  
	gen s`i'= sum_bull_likes_`i' + sum_bear_likes_`i'
	replace sum_bull_likes_`i'=. if s`i'==0
	replace sum_bear_likes_`i'=. if s`i'==0 
drop s`i'	
}

keep userid symbolid date bull bear sum_bull_likes_1 sum_bear_likes_1 sum_bull_likes_2_10 sum_bear_likes_2_10 sum_bull_likes_11_30 sum_bear_likes_11_30 sum_bull_likes_31_50 sum_bear_likes_31_50

qui compress
save temp_likes, replace



**********************************************

use temp_likes, clear

foreach kk in 1 2_10 11_30 31_50 {
	
eststo L_t`kk'_bull: reghdfe sum_bull_likes_`kk' bull, absorb(i.userid i.symbolid#i.date) vce(cl userid)
	qui sum sum_bull_likes_`kk' if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bull]/avg)*100

eststo L_t`kk'_bear: reghdfe sum_bear_likes_`kk' bear, absorb(i.userid i.symbolid#i.date) vce(cl userid)
	qui sum sum_bear_likes_`kk' if e(sample)==1
	qui estadd scalar avg = r(mean)
	scalar define avg= r(mean)
	qui estadd scalar effect_size = (_b[bear]/avg)*100

}
* -------------------- *


cap estadd local userFE "Y" : *
cap estadd local daysymbolFE "Y" : *

local stats_opts " stats(N N_clust r2 avg effect_size userFE daysymbolFE, fmt(%18.0fc %18.0fc %12.2fc %12.2fc %12.0fc) labels("\# obs." "\# clusters (users)" "$\textit{R}^2$" "Mean of dependent var.(\%)" "Effect size (\% of mean)" "User FE" "Day x Symbol FE") ) " 

#delimit ; 
local opts   "b(%16.2fc) se(%16.2fc) brackets booktabs  star(* 0.10 ** 0.05 *** 0.01) nonotes lines 
mtitles("Bullish" "Bearish" "Bullish" "Bearish" "Bullish" "Bearish" "Bullish" "Bearish" "Bullish" "Bearish")
mgroups("N of liked msgs\textsubscript{s,t+1}" "N of liked msgs\textsubscript{s,(t+2 $\rightarrow$ t+10)}" "N of liked msgs\textsubscript{s,(t+11 $\rightarrow$ t+30)}" "N of liked msgs\textsubscript{s,(t+31 $\rightarrow$ t+50)}" 
, pattern(1 0 1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))  " ;     
#delimit cr 

cd "`=tabledir'"
esttab L* using T6_Likes.tex, `opts' `stats_opts' drop(_cons) coef(bull "$\mathbbm{1}$ Declare Bull\textsubscript{\textbf{s,t}}" bear "$\mathbbm{1}$ Declare Bear\textsubscript{\textbf{s,t}}") replace  
cd "`=maindir'"

********************************************

